/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tan.k.view;

import java.awt.Dimension;
import java.util.ArrayList;
import java.util.List;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JCheckBox;
import javax.swing.JRadioButton;
import javax.swing.JToggleButton;
import tan.k.controller.TanKController.Loop;
import tan.k.controller.TanKController.TankNumber;
import tan.k.controller.TanKController.Wave;

/**
 *
 * @author gabriel,ricardo
 */
public class MainFrame extends javax.swing.JFrame {

    //Current values
    private double currentAmplitide;
    private double currentPeriod;
    private Wave currentWave;
    private JToggleButton currentWaveButton;
    private double currentSetPoint;
    private TankNumber currentPV;
    private Loop currentLoop;
    private String currentIp;
    private int currentPort;
    private int currentWriteChannel;
    //Events
    private ChangeParameterEvent setPointChange;
    private ChangeParameterEvent processVariableChange;
    private ChangeParameterEvent amplitudeChange;
    private ChangeParameterEvent periodChange;
    private ChangeParameterEvent waveChange;
    private ChangeParameterEvent loopChange;
    private ChangeParameterEvent ipChange;
    private ChangeParameterEvent portChange;
    private ChangeParameterEvent writeChange;
    private ChangeParameterEvent applyClicked;
    private ChangeParameterEvent connectClicked;
    private DefaultComboBoxModel<ComboItem> pvItems;
    private List<String> pvItemsString;
    private ChangeParameterEvent stopClicked;

    /**
     * Creates new form MainFrame
     */
    public MainFrame() {
        this.currentAmplitide = 0;
        this.currentPeriod = 1;
        this.currentWave = Wave.STEP;
        this.currentSetPoint = 0;
        this.currentPV = TankNumber.TANK_1;
        this.currentLoop = Loop.OPENED;
        //this.currentIp = "127.0.0.1";
        this.currentIp = "10.13.99.69";
        this.currentPort = 20081;
        this.currentWriteChannel = 0;
        initComponents();

        graphPanel3.disableLegend();
        graphPanel3.addSerie("Sinal para configuracao");
    }

    /*public String[] getSelectedInputs(){
     //TODO: Implement this method
     List<JCheckBox> inputs = new ArrayList<JCheckBox>();
     }*/
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        writeChannelChooser = new javax.swing.ButtonGroup();
        loopTypeChooser = new javax.swing.ButtonGroup();
        waveTypeChooser = new javax.swing.ButtonGroup();
        sidebar = new javax.swing.JPanel();
        readTitle = new javax.swing.JPanel();
        readToggler = new javax.swing.JLabel();
        readBox = new javax.swing.JPanel();
        inputTable = new javax.swing.JPanel();
        inputColumn0 = new javax.swing.JPanel();
        input0 = new javax.swing.JCheckBox();
        input1 = new javax.swing.JCheckBox();
        inputColumn1 = new javax.swing.JPanel();
        input2 = new javax.swing.JCheckBox();
        input3 = new javax.swing.JCheckBox();
        inputColumn2 = new javax.swing.JPanel();
        input4 = new javax.swing.JCheckBox();
        input5 = new javax.swing.JCheckBox();
        inputColumn3 = new javax.swing.JPanel();
        input6 = new javax.swing.JCheckBox();
        input7 = new javax.swing.JCheckBox();
        write = new javax.swing.JPanel();
        writeToggler = new javax.swing.JLabel();
        writeBox = new javax.swing.JPanel();
        outputTable = new javax.swing.JPanel();
        outputColumn0 = new javax.swing.JPanel();
        output0 = new javax.swing.JRadioButton();
        output1 = new javax.swing.JRadioButton();
        outputColumn1 = new javax.swing.JPanel();
        output2 = new javax.swing.JRadioButton();
        output3 = new javax.swing.JRadioButton();
        outputColumn2 = new javax.swing.JPanel();
        output4 = new javax.swing.JRadioButton();
        output5 = new javax.swing.JRadioButton();
        outputColumn3 = new javax.swing.JPanel();
        output6 = new javax.swing.JRadioButton();
        output7 = new javax.swing.JRadioButton();
        jSeparator1 = new javax.swing.JSeparator();
        jSeparator2 = new javax.swing.JSeparator();
        openedLoopSettings = new javax.swing.JPanel();
        waveType = new javax.swing.JPanel();
        sinus = new javax.swing.JToggleButton();
        sawtooth = new javax.swing.JToggleButton();
        square = new javax.swing.JToggleButton();
        step = new javax.swing.JToggleButton();
        random = new javax.swing.JToggleButton();
        outputSettings = new javax.swing.JPanel();
        waveParams = new javax.swing.JPanel();
        amplitude = new javax.swing.JPanel();
        amplitudeLabel = new javax.swing.JLabel();
        amplitudeField = new javax.swing.JFormattedTextField();
        period = new javax.swing.JPanel();
        periodLabel = new javax.swing.JLabel();
        periodField = new javax.swing.JFormattedTextField();
        frequency = new javax.swing.JPanel();
        frequencyLabel = new javax.swing.JLabel();
        frequencyField = new javax.swing.JFormattedTextField();
        graphPanel3 = new tan.k.view.GraphPanel();
        jLabelVoltage = new javax.swing.JLabel();
        jLabelSeconds = new javax.swing.JLabel();
        jLabelHertz = new javax.swing.JLabel();
        outputPreview = new java.awt.Canvas();
        closedLoopSettings = new javax.swing.JPanel();
        controlSettings = new javax.swing.JPanel();
        waveParams1 = new javax.swing.JPanel();
        setPoint = new javax.swing.JPanel();
        setPointLabel = new javax.swing.JLabel();
        setPointField = new javax.swing.JFormattedTextField();
        jLabelVoltage1 = new javax.swing.JLabel();
        processVariable = new javax.swing.JPanel();
        processVariableLabel = new javax.swing.JLabel();
        processVariableField = new javax.swing.JComboBox();
        apply = new javax.swing.JButton();
        jButtonPreview = new javax.swing.JButton();
        loopChooser = new javax.swing.JPanel();
        openedLoop = new javax.swing.JRadioButton();
        closedLoop = new javax.swing.JRadioButton();
        jButtonStop = new javax.swing.JButton();
        ipPort = new javax.swing.JPanel();
        ipPortToggler = new javax.swing.JLabel();
        ipPortBox = new javax.swing.JPanel();
        ipPortWrapper = new javax.swing.JPanel();
        ipPortLabel = new javax.swing.JLabel();
        ipPortField = new javax.swing.JFormattedTextField();
        connect = new javax.swing.JButton();
        graphPanel1 = new tan.k.view.GraphPanel();
        graphPanel2 = new tan.k.view.GraphPanel();
        jToggleButtonConfiguration = new javax.swing.JToggleButton();
        statusConnectedLabel = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenu2 = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Tank");
        setMinimumSize(new java.awt.Dimension(1300, 720));

        sidebar.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        sidebar.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        sidebar.setMinimumSize(new java.awt.Dimension(260, 100));
        sidebar.setBackground(java.awt.SystemColor.control);

        readTitle.setBackground(new java.awt.Color(158, 158, 158));

        readToggler.setFont(new java.awt.Font("Ubuntu", 0, 15)); // NOI18N
        readToggler.setText("Leitura");
        readToggler.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                readTogglerMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout readTitleLayout = new javax.swing.GroupLayout(readTitle);
        readTitle.setLayout(readTitleLayout);
        readTitleLayout.setHorizontalGroup(
            readTitleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(readToggler, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        readTitleLayout.setVerticalGroup(
            readTitleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(readToggler)
        );

        inputColumn0.setMinimumSize(new java.awt.Dimension(65, 100));
        inputColumn0.setPreferredSize(new java.awt.Dimension(65, 50));

        input0.setText("A0");
        input0.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                updatePVSelector(evt);
            }
        });

        input1.setText("A1");
        input1.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                updatePVSelector(evt);
            }
        });

        javax.swing.GroupLayout inputColumn0Layout = new javax.swing.GroupLayout(inputColumn0);
        inputColumn0.setLayout(inputColumn0Layout);
        inputColumn0Layout.setHorizontalGroup(
            inputColumn0Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(inputColumn0Layout.createSequentialGroup()
                .addGroup(inputColumn0Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(input0)
                    .addComponent(input1))
                .addGap(0, 22, Short.MAX_VALUE))
        );
        inputColumn0Layout.setVerticalGroup(
            inputColumn0Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(inputColumn0Layout.createSequentialGroup()
                .addComponent(input0)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(input1)
                .addGap(0, 0, Short.MAX_VALUE))
        );

        inputColumn1.setMinimumSize(new java.awt.Dimension(65, 100));
        inputColumn1.setPreferredSize(new java.awt.Dimension(65, 50));

        input2.setText("A2");
        input2.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                updatePVSelector(evt);
            }
        });

        input3.setText("A3");
        input3.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                updatePVSelector(evt);
            }
        });

        javax.swing.GroupLayout inputColumn1Layout = new javax.swing.GroupLayout(inputColumn1);
        inputColumn1.setLayout(inputColumn1Layout);
        inputColumn1Layout.setHorizontalGroup(
            inputColumn1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(inputColumn1Layout.createSequentialGroup()
                .addGroup(inputColumn1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(input2)
                    .addComponent(input3))
                .addGap(0, 22, Short.MAX_VALUE))
        );
        inputColumn1Layout.setVerticalGroup(
            inputColumn1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(inputColumn1Layout.createSequentialGroup()
                .addComponent(input2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(input3)
                .addGap(0, 0, Short.MAX_VALUE))
        );

        inputColumn2.setMinimumSize(new java.awt.Dimension(65, 100));
        inputColumn2.setPreferredSize(new java.awt.Dimension(65, 50));

        input4.setText("A4");
        input4.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                updatePVSelector(evt);
            }
        });

        input5.setText("A5");
        input5.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                updatePVSelector(evt);
            }
        });

        javax.swing.GroupLayout inputColumn2Layout = new javax.swing.GroupLayout(inputColumn2);
        inputColumn2.setLayout(inputColumn2Layout);
        inputColumn2Layout.setHorizontalGroup(
            inputColumn2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(inputColumn2Layout.createSequentialGroup()
                .addGroup(inputColumn2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(input4)
                    .addComponent(input5))
                .addGap(0, 22, Short.MAX_VALUE))
        );
        inputColumn2Layout.setVerticalGroup(
            inputColumn2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(inputColumn2Layout.createSequentialGroup()
                .addComponent(input4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(input5)
                .addGap(0, 0, Short.MAX_VALUE))
        );

        inputColumn3.setMinimumSize(new java.awt.Dimension(65, 100));
        inputColumn3.setPreferredSize(new java.awt.Dimension(65, 50));

        input6.setText("A6");
        input6.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                updatePVSelector(evt);
            }
        });

        input7.setText("A7");
        input7.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                updatePVSelector(evt);
            }
        });

        javax.swing.GroupLayout inputColumn3Layout = new javax.swing.GroupLayout(inputColumn3);
        inputColumn3.setLayout(inputColumn3Layout);
        inputColumn3Layout.setHorizontalGroup(
            inputColumn3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(inputColumn3Layout.createSequentialGroup()
                .addGroup(inputColumn3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(input6)
                    .addComponent(input7))
                .addGap(0, 22, Short.MAX_VALUE))
        );
        inputColumn3Layout.setVerticalGroup(
            inputColumn3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(inputColumn3Layout.createSequentialGroup()
                .addComponent(input6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(input7)
                .addGap(0, 0, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout inputTableLayout = new javax.swing.GroupLayout(inputTable);
        inputTable.setLayout(inputTableLayout);
        inputTableLayout.setHorizontalGroup(
            inputTableLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(inputTableLayout.createSequentialGroup()
                .addComponent(inputColumn0, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, 0)
                .addComponent(inputColumn1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, 0)
                .addComponent(inputColumn2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, 0)
                .addComponent(inputColumn3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        inputTableLayout.setVerticalGroup(
            inputTableLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(inputColumn0, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addComponent(inputColumn1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addComponent(inputColumn2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addComponent(inputColumn3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        javax.swing.GroupLayout readBoxLayout = new javax.swing.GroupLayout(readBox);
        readBox.setLayout(readBoxLayout);
        readBoxLayout.setHorizontalGroup(
            readBoxLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(readBoxLayout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(inputTable, javax.swing.GroupLayout.PREFERRED_SIZE, 268, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );
        readBoxLayout.setVerticalGroup(
            readBoxLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, readBoxLayout.createSequentialGroup()
                .addComponent(inputTable, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, 0))
        );

        write.setBackground(new java.awt.Color(158, 158, 158));

        writeToggler.setFont(new java.awt.Font("Ubuntu", 0, 15)); // NOI18N
        writeToggler.setText("Escrita");
        writeToggler.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                writeTogglerMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout writeLayout = new javax.swing.GroupLayout(write);
        write.setLayout(writeLayout);
        writeLayout.setHorizontalGroup(
            writeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(writeToggler, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        writeLayout.setVerticalGroup(
            writeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(writeToggler)
        );

        writeBox.setPreferredSize(new Dimension(100,100));
        writeBox.setPreferredSize(new java.awt.Dimension(357, 100));

        outputColumn0.setMinimumSize(new java.awt.Dimension(65, 100));
        outputColumn0.setPreferredSize(new java.awt.Dimension(65, 50));

        writeChannelChooser.add(output0);
        output0.setText("A0");

        writeChannelChooser.add(output1);
        output1.setText("A1");

        javax.swing.GroupLayout outputColumn0Layout = new javax.swing.GroupLayout(outputColumn0);
        outputColumn0.setLayout(outputColumn0Layout);
        outputColumn0Layout.setHorizontalGroup(
            outputColumn0Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(outputColumn0Layout.createSequentialGroup()
                .addGroup(outputColumn0Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(output0)
                    .addComponent(output1))
                .addGap(0, 22, Short.MAX_VALUE))
        );
        outputColumn0Layout.setVerticalGroup(
            outputColumn0Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(outputColumn0Layout.createSequentialGroup()
                .addComponent(output0)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(output1)
                .addGap(0, 0, Short.MAX_VALUE))
        );

        outputColumn1.setMinimumSize(new java.awt.Dimension(65, 100));
        outputColumn1.setPreferredSize(new java.awt.Dimension(65, 50));

        writeChannelChooser.add(output2);
        output2.setText("A2");

        writeChannelChooser.add(output3);
        output3.setText("A3");

        javax.swing.GroupLayout outputColumn1Layout = new javax.swing.GroupLayout(outputColumn1);
        outputColumn1.setLayout(outputColumn1Layout);
        outputColumn1Layout.setHorizontalGroup(
            outputColumn1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(outputColumn1Layout.createSequentialGroup()
                .addGroup(outputColumn1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(output2)
                    .addComponent(output3))
                .addGap(0, 22, Short.MAX_VALUE))
        );
        outputColumn1Layout.setVerticalGroup(
            outputColumn1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(outputColumn1Layout.createSequentialGroup()
                .addComponent(output2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(output3)
                .addGap(0, 0, Short.MAX_VALUE))
        );

        outputColumn2.setMinimumSize(new java.awt.Dimension(65, 100));
        outputColumn2.setPreferredSize(new java.awt.Dimension(65, 50));

        writeChannelChooser.add(output4);
        output4.setText("A4");

        writeChannelChooser.add(output5);
        output5.setText("A5");

        javax.swing.GroupLayout outputColumn2Layout = new javax.swing.GroupLayout(outputColumn2);
        outputColumn2.setLayout(outputColumn2Layout);
        outputColumn2Layout.setHorizontalGroup(
            outputColumn2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(outputColumn2Layout.createSequentialGroup()
                .addGroup(outputColumn2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(output4)
                    .addComponent(output5))
                .addGap(0, 22, Short.MAX_VALUE))
        );
        outputColumn2Layout.setVerticalGroup(
            outputColumn2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(outputColumn2Layout.createSequentialGroup()
                .addComponent(output4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(output5)
                .addGap(0, 0, Short.MAX_VALUE))
        );

        outputColumn3.setMinimumSize(new java.awt.Dimension(65, 100));
        outputColumn3.setPreferredSize(new java.awt.Dimension(65, 50));

        writeChannelChooser.add(output6);
        output6.setText("A6");

        writeChannelChooser.add(output7);
        output7.setText("A7");

        javax.swing.GroupLayout outputColumn3Layout = new javax.swing.GroupLayout(outputColumn3);
        outputColumn3.setLayout(outputColumn3Layout);
        outputColumn3Layout.setHorizontalGroup(
            outputColumn3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(outputColumn3Layout.createSequentialGroup()
                .addGroup(outputColumn3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(output6)
                    .addComponent(output7))
                .addGap(0, 22, Short.MAX_VALUE))
        );
        outputColumn3Layout.setVerticalGroup(
            outputColumn3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(outputColumn3Layout.createSequentialGroup()
                .addComponent(output6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(output7)
                .addGap(0, 0, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout outputTableLayout = new javax.swing.GroupLayout(outputTable);
        outputTable.setLayout(outputTableLayout);
        outputTableLayout.setHorizontalGroup(
            outputTableLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(outputTableLayout.createSequentialGroup()
                .addComponent(outputColumn0, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, 0)
                .addComponent(outputColumn1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, 0)
                .addComponent(outputColumn2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, 0)
                .addComponent(outputColumn3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        outputTableLayout.setVerticalGroup(
            outputTableLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(outputColumn0, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addComponent(outputColumn1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addComponent(outputColumn2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addComponent(outputColumn3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        //waveType.setAlignmentX(Component.CENTER_ALIGNMENT);

        sinus.setToolTipText("Senoidal");
        sinus.setSelected(true);
        if(!currentWave.equals(Wave.SINUSOID)){
            currentWaveButton = sinus;
            currentWave = Wave.SINUSOID;
        }
        waveTypeChooser.add(sinus);
        sinus.setIcon(new javax.swing.ImageIcon(getClass().getResource("/tan/k/resource/sinus.png"))); // NOI18N
        sinus.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                sinusItemStateChanged(evt);
            }
        });

        sawtooth.setToolTipText("Dente de serra");
        waveTypeChooser.add(sawtooth);
        sawtooth.setIcon(new javax.swing.ImageIcon(getClass().getResource("/tan/k/resource/sawtooth.png"))); // NOI18N
        sawtooth.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                sawtoothItemStateChanged(evt);
            }
        });

        square.setToolTipText("Quadrada");
        waveTypeChooser.add(square);
        square.setIcon(new javax.swing.ImageIcon(getClass().getResource("/tan/k/resource/square.png"))); // NOI18N
        square.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                squareItemStateChanged(evt);
            }
        });

        step.setToolTipText("Degrau");
        waveTypeChooser.add(step);
        step.setIcon(new javax.swing.ImageIcon(getClass().getResource("/tan/k/resource/step.png"))); // NOI18N
        step.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                stepItemStateChanged(evt);
            }
        });

        random.setToolTipText("Aleatória");
        waveTypeChooser.add(random);
        random.setIcon(new javax.swing.ImageIcon(getClass().getResource("/tan/k/resource/random.png"))); // NOI18N
        random.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                randomItemStateChanged(evt);
            }
        });

        javax.swing.GroupLayout waveTypeLayout = new javax.swing.GroupLayout(waveType);
        waveType.setLayout(waveTypeLayout);
        waveTypeLayout.setHorizontalGroup(
            waveTypeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(waveTypeLayout.createSequentialGroup()
                .addGap(0, 52, Short.MAX_VALUE)
                .addComponent(sinus)
                .addGap(0, 0, 0)
                .addComponent(sawtooth)
                .addGap(0, 0, 0)
                .addComponent(square)
                .addGap(0, 0, 0)
                .addComponent(step)
                .addGap(0, 0, 0)
                .addComponent(random)
                .addGap(0, 52, Short.MAX_VALUE))
        );
        waveTypeLayout.setVerticalGroup(
            waveTypeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(waveTypeLayout.createSequentialGroup()
                .addGroup(waveTypeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(random)
                    .addComponent(step)
                    .addComponent(square)
                    .addGroup(waveTypeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(sinus)
                        .addComponent(sawtooth)))
                .addGap(0, 0, 0))
        );

        waveParams.setMinimumSize(new java.awt.Dimension(169, 96));

        amplitude.setPreferredSize(new java.awt.Dimension(199, 28));

        amplitudeLabel.setText("Amplitude");

        amplitudeField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                amplitudeFieldKeyPressed(evt);
            }
            public void keyPressed(java.awt.event.KeyEvent evt) {
                amplitudeFieldKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                amplitudeFieldKeyPressed(evt);
            }
        });

        javax.swing.GroupLayout amplitudeLayout = new javax.swing.GroupLayout(amplitude);
        amplitude.setLayout(amplitudeLayout);
        amplitudeLayout.setHorizontalGroup(
            amplitudeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(amplitudeLayout.createSequentialGroup()
                .addGap(0, 0, 0)
                .addComponent(amplitudeLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(amplitudeField, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, 0))
        );
        amplitudeLayout.setVerticalGroup(
            amplitudeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(amplitudeLayout.createSequentialGroup()
                .addGroup(amplitudeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(amplitudeField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(amplitudeLabel))
                .addGap(0, 0, Short.MAX_VALUE))
        );

        period.setPreferredSize(new java.awt.Dimension(199, 28));

        periodLabel.setText("Período");

        periodField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                periodFieldKeyTyped(evt);
            }
            public void keyPressed(java.awt.event.KeyEvent evt) {
                periodFieldKeyTyped(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                periodFieldKeyTyped(evt);
            }
        });

        javax.swing.GroupLayout periodLayout = new javax.swing.GroupLayout(period);
        period.setLayout(periodLayout);
        periodLayout.setHorizontalGroup(
            periodLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(periodLayout.createSequentialGroup()
                .addGap(0, 0, 0)
                .addComponent(periodLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 45, Short.MAX_VALUE)
                .addComponent(periodField, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, 0))
        );
        periodLayout.setVerticalGroup(
            periodLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(periodLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(periodLabel)
                .addComponent(periodField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        frequencyLabel.setText("Frequência");

        frequencyField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                frequencyFieldKeyPressed(evt);
            }
            public void keyPressed(java.awt.event.KeyEvent evt) {
                frequencyFieldKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                frequencyFieldKeyPressed(evt);
            }
        });

        javax.swing.GroupLayout frequencyLayout = new javax.swing.GroupLayout(frequency);
        frequency.setLayout(frequencyLayout);
        frequencyLayout.setHorizontalGroup(
            frequencyLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(frequencyLayout.createSequentialGroup()
                .addComponent(frequencyLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(frequencyField, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, 0))
        );
        frequencyLayout.setVerticalGroup(
            frequencyLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, frequencyLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(frequencyField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(frequencyLabel))
        );

        jLabelVoltage.setText("V");

        jLabelSeconds.setText("s");

        jLabelHertz.setText("Hz");

        javax.swing.GroupLayout waveParamsLayout = new javax.swing.GroupLayout(waveParams);
        waveParams.setLayout(waveParamsLayout);
        waveParamsLayout.setHorizontalGroup(
            waveParamsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(waveParamsLayout.createSequentialGroup()
                .addGroup(waveParamsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(graphPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, 312, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(waveParamsLayout.createSequentialGroup()
                        .addGroup(waveParamsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(frequency, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(period, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 174, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(amplitude, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 174, Short.MAX_VALUE))
                        .addGap(6, 6, 6)
                        .addGroup(waveParamsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabelHertz)
                            .addComponent(jLabelSeconds, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabelVoltage))))
                .addContainerGap(21, Short.MAX_VALUE))
        );
        waveParamsLayout.setVerticalGroup(
            waveParamsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(waveParamsLayout.createSequentialGroup()
                .addGroup(waveParamsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(amplitude, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabelVoltage, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(0, 0, 0)
                .addGroup(waveParamsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(period, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabelSeconds, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(0, 0, 0)
                .addGroup(waveParamsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(frequency, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabelHertz, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(graphPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout outputSettingsLayout = new javax.swing.GroupLayout(outputSettings);
        outputSettings.setLayout(outputSettingsLayout);
        outputSettingsLayout.setHorizontalGroup(
            outputSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(outputSettingsLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(waveParams, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(outputPreview, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        outputSettingsLayout.setVerticalGroup(
            outputSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(outputSettingsLayout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addGroup(outputSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(waveParams, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(outputPreview, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(0, 0, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout openedLoopSettingsLayout = new javax.swing.GroupLayout(openedLoopSettings);
        openedLoopSettings.setLayout(openedLoopSettingsLayout);
        openedLoopSettingsLayout.setHorizontalGroup(
            openedLoopSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(openedLoopSettingsLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(outputSettings, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
            .addGroup(openedLoopSettingsLayout.createSequentialGroup()
                .addComponent(waveType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );
        openedLoopSettingsLayout.setVerticalGroup(
            openedLoopSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(openedLoopSettingsLayout.createSequentialGroup()
                .addComponent(waveType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 15, Short.MAX_VALUE)
                .addComponent(outputSettings, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        closedLoopSettings.setVisible(false);

        waveParams1.setMinimumSize(new java.awt.Dimension(169, 96));

        setPoint.setPreferredSize(new java.awt.Dimension(199, 33));

        setPointLabel.setText("SP");

        setPointField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                setPointFieldActionPerformed(evt);
            }
        });

        jLabelVoltage1.setText("cm");

        javax.swing.GroupLayout setPointLayout = new javax.swing.GroupLayout(setPoint);
        setPoint.setLayout(setPointLayout);
        setPointLayout.setHorizontalGroup(
            setPointLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(setPointLayout.createSequentialGroup()
                .addGap(0, 0, 0)
                .addComponent(setPointLabel)
                .addGap(30, 30, 30)
                .addComponent(setPointField, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(3, 3, 3)
                .addComponent(jLabelVoltage1))
        );
        setPointLayout.setVerticalGroup(
            setPointLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(setPointLayout.createSequentialGroup()
                .addGap(5, 5, 5)
                .addGroup(setPointLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(setPointLabel)
                    .addComponent(setPointField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelVoltage1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
        );

        processVariable.setPreferredSize(new java.awt.Dimension(199, 28));

        processVariableLabel.setText("PV");

        pvItems =  new javax.swing.DefaultComboBoxModel<>();
        processVariableField.setModel(pvItems);
        pvItemsString = new ArrayList<>();
        processVariableField.setEnabled(false);
        processVariableField.setPreferredSize(new java.awt.Dimension(75, 28));

        javax.swing.GroupLayout processVariableLayout = new javax.swing.GroupLayout(processVariable);
        processVariable.setLayout(processVariableLayout);
        processVariableLayout.setHorizontalGroup(
            processVariableLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(processVariableLayout.createSequentialGroup()
                .addGap(0, 0, 0)
                .addComponent(processVariableLabel)
                .addGap(30, 30, 30)
                .addComponent(processVariableField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(22, 22, 22))
        );
        processVariableLayout.setVerticalGroup(
            processVariableLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(processVariableLayout.createSequentialGroup()
                .addGap(0, 0, 0)
                .addGroup(processVariableLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(processVariableField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(processVariableLabel)))
        );

        javax.swing.GroupLayout waveParams1Layout = new javax.swing.GroupLayout(waveParams1);
        waveParams1.setLayout(waveParams1Layout);
        waveParams1Layout.setHorizontalGroup(
            waveParams1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(waveParams1Layout.createSequentialGroup()
                .addGap(0, 0, 0)
                .addGroup(waveParams1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(processVariable, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 206, Short.MAX_VALUE)
                    .addComponent(setPoint, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 206, Short.MAX_VALUE))
                .addGap(0, 0, 0))
        );
        waveParams1Layout.setVerticalGroup(
            waveParams1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(waveParams1Layout.createSequentialGroup()
                .addGap(0, 0, 0)
                .addComponent(setPoint, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(processVariable, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, 0))
        );

        javax.swing.GroupLayout controlSettingsLayout = new javax.swing.GroupLayout(controlSettings);
        controlSettings.setLayout(controlSettingsLayout);
        controlSettingsLayout.setHorizontalGroup(
            controlSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(controlSettingsLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(waveParams1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        controlSettingsLayout.setVerticalGroup(
            controlSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(controlSettingsLayout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(waveParams1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout closedLoopSettingsLayout = new javax.swing.GroupLayout(closedLoopSettings);
        closedLoopSettings.setLayout(closedLoopSettingsLayout);
        closedLoopSettingsLayout.setHorizontalGroup(
            closedLoopSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(closedLoopSettingsLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(controlSettings, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        closedLoopSettingsLayout.setVerticalGroup(
            closedLoopSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(closedLoopSettingsLayout.createSequentialGroup()
                .addGap(0, 0, 0)
                .addComponent(controlSettings, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        apply.setText("Aplicar");
        apply.setEnabled(false);
        apply.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                applyMouseClicked(evt);
            }
        });

        jButtonPreview.setText("Pré-Visualizar");
        jButtonPreview.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonPreviewActionPerformed(evt);
            }
        });

        loopChooser.setMinimumSize(new java.awt.Dimension(100, 50));
        loopChooser.setPreferredSize(new java.awt.Dimension(100, 50));

        openedLoop.setSelected(true);
        loopTypeChooser.add(openedLoop);
        openedLoop.setText("Malha aberta");
        openedLoop.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                openedLoopItemStateChanged(evt);
            }
        });

        loopTypeChooser.add(closedLoop);
        closedLoop.setText("Malha Fechada");
        closedLoop.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                closedLoopItemStateChanged(evt);
            }
        });
        closedLoop.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                closedLoopActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout loopChooserLayout = new javax.swing.GroupLayout(loopChooser);
        loopChooser.setLayout(loopChooserLayout);
        loopChooserLayout.setHorizontalGroup(
            loopChooserLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, loopChooserLayout.createSequentialGroup()
                .addGap(25, 25, 25)
                .addComponent(openedLoop)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(closedLoop)
                .addGap(25, 25, 25))
        );
        loopChooserLayout.setVerticalGroup(
            loopChooserLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(loopChooserLayout.createSequentialGroup()
                .addContainerGap(17, Short.MAX_VALUE)
                .addGroup(loopChooserLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(openedLoop)
                    .addComponent(closedLoop))
                .addGap(9, 9, 9))
        );

        jButtonStop.setText("Interromper");
        jButtonStop.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButtonStopMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout writeBoxLayout = new javax.swing.GroupLayout(writeBox);
        writeBox.setLayout(writeBoxLayout);
        writeBoxLayout.setHorizontalGroup(
            writeBoxLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(openedLoopSettings, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
            .addComponent(jSeparator1)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, writeBoxLayout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(outputTable, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
            .addGroup(writeBoxLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(writeBoxLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(loopChooser, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 334, Short.MAX_VALUE)
                    .addGroup(writeBoxLayout.createSequentialGroup()
                        .addGroup(writeBoxLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(writeBoxLayout.createSequentialGroup()
                                .addComponent(jButtonPreview)
                                .addGap(33, 33, 33)
                                .addComponent(jButtonStop))
                            .addComponent(closedLoopSettings, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(33, 33, 33)
                        .addComponent(apply)))
                .addContainerGap())
            .addComponent(jSeparator2)
        );
        writeBoxLayout.setVerticalGroup(
            writeBoxLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(writeBoxLayout.createSequentialGroup()
                .addGap(0, 0, 0)
                .addComponent(loopChooser, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, 0)
                .addComponent(outputTable, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(5, 5, 5)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(1, 1, 1)
                .addComponent(openedLoopSettings, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(closedLoopSettings, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(writeBoxLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(apply)
                    .addComponent(jButtonPreview)
                    .addComponent(jButtonStop))
                .addContainerGap())
        );

        ipPort.setBackground(new java.awt.Color(158, 158, 158));
        ipPort.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                ipPortMouseClicked(evt);
            }
        });

        ipPortToggler.setFont(new java.awt.Font("Ubuntu", 0, 15)); // NOI18N
        ipPortToggler.setText("IP / Porta");

        javax.swing.GroupLayout ipPortLayout = new javax.swing.GroupLayout(ipPort);
        ipPort.setLayout(ipPortLayout);
        ipPortLayout.setHorizontalGroup(
            ipPortLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(ipPortToggler, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        ipPortLayout.setVerticalGroup(
            ipPortLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(ipPortToggler)
        );

        ipPortLabel.setText("IP:Porta");

        ipPortField.setText(this.currentIp+":"+this.currentPort);
        ipPortField.setText("10.13.99.69:20081");
        ipPortField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ipPortFieldActionPerformed(evt);
            }
        });

        connect.setText("Conectar");
        connect.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                connectMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout ipPortWrapperLayout = new javax.swing.GroupLayout(ipPortWrapper);
        ipPortWrapper.setLayout(ipPortWrapperLayout);
        ipPortWrapperLayout.setHorizontalGroup(
            ipPortWrapperLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(ipPortWrapperLayout.createSequentialGroup()
                .addGap(0, 0, 0)
                .addComponent(ipPortLabel)
                .addGap(18, 18, 18)
                .addComponent(ipPortField, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(connect)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        ipPortWrapperLayout.setVerticalGroup(
            ipPortWrapperLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(ipPortWrapperLayout.createSequentialGroup()
                .addGap(5, 5, 5)
                .addGroup(ipPortWrapperLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(ipPortLabel)
                    .addComponent(ipPortField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(connect)))
        );

        javax.swing.GroupLayout ipPortBoxLayout = new javax.swing.GroupLayout(ipPortBox);
        ipPortBox.setLayout(ipPortBoxLayout);
        ipPortBoxLayout.setHorizontalGroup(
            ipPortBoxLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(ipPortBoxLayout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addComponent(ipPortWrapper, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        ipPortBoxLayout.setVerticalGroup(
            ipPortBoxLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(ipPortBoxLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(ipPortWrapper, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout sidebarLayout = new javax.swing.GroupLayout(sidebar);
        sidebar.setLayout(sidebarLayout);
        sidebarLayout.setHorizontalGroup(
            sidebarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(readTitle, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(readBox, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(write, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, sidebarLayout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(writeBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addComponent(ipPort, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(ipPortBox, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        sidebarLayout.setVerticalGroup(
            sidebarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(sidebarLayout.createSequentialGroup()
                .addGap(0, 0, 0)
                .addComponent(ipPort, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, 0)
                .addComponent(ipPortBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, 0)
                .addComponent(readTitle, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, 0)
                .addComponent(readBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, 0)
                .addComponent(write, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, 0)
                .addComponent(writeBox, javax.swing.GroupLayout.DEFAULT_SIZE, 535, Short.MAX_VALUE)
                .addGap(0, 0, 0))
        );

        graphPanel1.setyAxisLabel("Altura(cm)");
        graphPanel1.setxAxisLabel("Tempo(s)");

        graphPanel2.setyAxisLabel("Volts(V)");
        graphPanel2.setxAxisLabel("Tempo(s)");

        jToggleButtonConfiguration.setIcon(new javax.swing.ImageIcon(getClass().getResource("/tan/k/resource/Settings_Icon_32.png"))); // NOI18N
        jToggleButtonConfiguration.setMaximumSize(new java.awt.Dimension(32, 32));
        jToggleButtonConfiguration.setMinimumSize(new java.awt.Dimension(32, 32));
        jToggleButtonConfiguration.setPreferredSize(new java.awt.Dimension(32, 43));
        jToggleButtonConfiguration.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jToggleButtonConfigurationActionPerformed(evt);
            }
        });

        statusConnectedLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/tan/k/resource/ball_red.png"))); // NOI18N
        statusConnectedLabel.setText("Não Conectado");

        jMenu1.setText("File");
        jMenuBar1.add(jMenu1);

        jMenu2.setText("Edit");
        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(sidebar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(graphPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 909, Short.MAX_VALUE)
                            .addComponent(graphPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jToggleButtonConfiguration, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(statusConnectedLabel))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(6, 6, 6)
                .addComponent(jToggleButtonConfiguration, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(graphPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(graphPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(sidebar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(statusConnectedLabel)
                .addGap(6, 6, 6))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void ipPortFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ipPortFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_ipPortFieldActionPerformed

    private void ipPortMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_ipPortMouseClicked
        ipPortBox.setVisible(!ipPortBox.isVisible());
    }//GEN-LAST:event_ipPortMouseClicked

    private void setPointFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_setPointFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_setPointFieldActionPerformed

    private void writeTogglerMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_writeTogglerMouseClicked
        writeBox.setVisible(!writeBox.isVisible());
    }//GEN-LAST:event_writeTogglerMouseClicked

    private void updatePVSelector(java.awt.event.ItemEvent evt){//GEN-FIRST:event_updatePVSelector
        JCheckBox clickedCBox = (JCheckBox) evt.getSource();
        String text = clickedCBox.getText();
        TankNumber t = text.equals("A0") ? TankNumber.TANK_1 : text.equals("A1") ? TankNumber.TANK_2 : null;
        if (clickedCBox.isSelected()) {
            pvItems.addElement(new ComboItem(t, text));
            pvItemsString.add(text);
        } else {
            pvItems.removeElementAt(pvItemsString.indexOf(text));
            pvItemsString.remove(text);
        }
        processVariableField.setEnabled(pvItems.getSize() > 0);
    }//GEN-LAST:event_updatePVSelector

    private void readTogglerMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_readTogglerMouseClicked
        readBox.setVisible(!readBox.isVisible());
    }//GEN-LAST:event_readTogglerMouseClicked

    private void closedLoopItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_closedLoopItemStateChanged
        JRadioButton self = (JRadioButton) evt.getSource();
        if (self.isSelected()) {
            openedLoopSettings.setVisible(false);
            closedLoopSettings.setVisible(true);
            writeBox.setPreferredSize(new Dimension(357, 140));
            jButtonPreview.setVisible(false);
            pack();
        }
    }//GEN-LAST:event_closedLoopItemStateChanged

    private void openedLoopItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_openedLoopItemStateChanged
        JRadioButton self = (JRadioButton) evt.getSource();
        if (self.isSelected()) {
            openedLoopSettings.setVisible(true);
            closedLoopSettings.setVisible(false);
            writeBox.setPreferredSize(new Dimension(357, 215));
            jButtonPreview.setVisible(true);
            pack();
        }
    }//GEN-LAST:event_openedLoopItemStateChanged

    private void jToggleButtonConfigurationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jToggleButtonConfigurationActionPerformed
        sidebar.setVisible(!sidebar.isVisible());
    }//GEN-LAST:event_jToggleButtonConfigurationActionPerformed

  private void periodFieldKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_periodFieldKeyTyped
      if (periodField.getText().matches("^.*[^0-9\\.]$")) {
          periodField.setText(periodField.getText().
                  substring(0, periodField.getText().length() - 1));
      }

      if (!"".equals(periodField.getText())) {
          periodField.setText(periodField.getText().replaceAll("[a-zA-Z]", ""));
          Double selectedPeriod = Double.parseDouble(periodField.getText());
          if (selectedPeriod != 0) {
              frequencyField.setValue(Double.toString(1.0 / selectedPeriod));
          } else {
              frequencyField.setValue("\u221E");
          }
      } else {
          frequencyField.setText("");
      }
  }//GEN-LAST:event_periodFieldKeyTyped

  private void applyMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_applyMouseClicked

      graphPanel1.addSerieIfInexistent("Tanque 1");
      graphPanel1.addSerieIfInexistent("Tanque 2");
      graphPanel2.addSerieIfInexistent("Sinal");

      graphPanel1.clearAll();
      graphPanel2.clearAll();

      if (!"".equals(setPointField.getText())) {
          double selectedSetPoint = Double.parseDouble(setPointField.getText());
          if (selectedSetPoint != currentSetPoint && null != setPointChange) {
              setPointChange.onChangeParameter(currentSetPoint = selectedSetPoint);
          }
      }
      if ((ComboItem) processVariableField.getSelectedItem() != null) {
          System.out.println("SP diferente de null");
          TankNumber selectedPV = ((ComboItem) processVariableField.getSelectedItem()).getValue();
          if (selectedPV != currentPV && null != processVariableChange) {

              processVariableChange.onChangeParameter(currentPV = selectedPV);
          }
      }

      if (!"".equals(amplitudeField.getText())) {
          double selectedAmplitude = Double.parseDouble(amplitudeField.getText());
          if (selectedAmplitude != currentAmplitide && null != amplitudeChange) {
              amplitudeChange.onChangeParameter(currentAmplitide = selectedAmplitude);
          }
      }
      if (!"".equals(periodField.getText())) {
          double selectedPeriod = Double.parseDouble(periodField.getText());
          if (selectedPeriod != currentPeriod && null != periodChange) {
              periodChange.onChangeParameter(currentPeriod = selectedPeriod);
          }
      }

      JToggleButton[] waves = {sinus, sawtooth, square, step, random};
      for (JToggleButton wave : waves) {
          if (wave.isSelected() && !wave.equals(currentWaveButton)) {
              waveChange.onChangeParameter(currentWave);
              currentWaveButton = wave;
          }
      }

      if (closedLoop.isSelected() ^ currentLoop.equals(Loop.CLOSED)) {
          loopChange.onChangeParameter(currentLoop = closedLoop.isSelected() ? Loop.CLOSED : Loop.OPENED);
      }

      if (null != applyClicked) {
          applyClicked.onChangeParameter(null);
      }

  }//GEN-LAST:event_applyMouseClicked

    private void randomItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_randomItemStateChanged
        if (((JToggleButton) evt.getSource()).isSelected()) {
            currentWave = Wave.RANDOM;
        }
    }//GEN-LAST:event_randomItemStateChanged

    private void connectMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_connectMouseClicked
        String[] ipPortArray = ipPortField.getText().split(":");
        if (ipPortArray.length > 1) {
            String ip = ipPortArray[0];
            int port = Integer.parseInt(ipPortArray[1]);

            if (!currentIp.equals(ip) && null != ipChange) {
                ipChange.onChangeParameter(currentIp = ip);
            }
            if (port != currentPort && null != portChange) {
                portChange.onChangeParameter(currentPort = port);
            }
        }
        apply.setEnabled(false);
        statusConnectedLabel.setText("Não Conectado");
        statusConnectedLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/tan/k/resource/ball_red.png")));
        connectClicked.onChangeParameter(null);
    }//GEN-LAST:event_connectMouseClicked

    private void stepItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_stepItemStateChanged
        if (((JToggleButton) evt.getSource()).isSelected()) {
            currentWave = Wave.STEP;
        }
    }//GEN-LAST:event_stepItemStateChanged

    private void squareItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_squareItemStateChanged
        if (((JToggleButton) evt.getSource()).isSelected()) {
            currentWave = Wave.SQUARE;
        }
    }//GEN-LAST:event_squareItemStateChanged

    private void sawtoothItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_sawtoothItemStateChanged
        if (((JToggleButton) evt.getSource()).isSelected()) {
            currentWave = Wave.SAWTOOTH;
        }
    }//GEN-LAST:event_sawtoothItemStateChanged

    private void sinusItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_sinusItemStateChanged
        if (((JToggleButton) evt.getSource()).isSelected()) {
            currentWave = Wave.SINUSOID;
        }
    }//GEN-LAST:event_sinusItemStateChanged

    private void jButtonPreviewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonPreviewActionPerformed
        double x = 0;
        double p = Double.parseDouble(periodField.getText());
        double a = Double.parseDouble(amplitudeField.getText());
        double y = 0;
        graphPanel3.clean("Sinal para configuracao");
        switch (currentWave) {
            case SINUSOID:
                while (x <= 1.05 * p) {
                    y = a/2 * Math.sin((x / p * 2 * Math.PI)) + a/2;
                    graphPanel3.addValue("Sinal para configuracao", x, y);
                    x = x + p / 40;
                }
                break;
            case SAWTOOTH:
                while (x <= 2 * p) {
                    double r = x % p;
                    y = (a / p) * r;
                    graphPanel3.addValue("Sinal para configuracao", x, y);
                    x = x + p / 1000;
                }
                break;
            case SQUARE:
                while (x <= 2 * p) {
                    double r = x % p;
                    y = r >= p / 2 ? 0 : a;
                    graphPanel3.addValue("Sinal para configuracao", x, y);
                    x = x + p / 1000;
                }
                break;
            case STEP:
                while (x <= 2 * p) {
                    y = a;
                    graphPanel3.addValue("Sinal para configuracao", x, y);
                    x = x + p / 1000;
                }
                break;
            case RANDOM:
                break;
        }
    }//GEN-LAST:event_jButtonPreviewActionPerformed

    private void closedLoopActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closedLoopActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_closedLoopActionPerformed

    private void jButtonStopMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButtonStopMouseClicked
        stopClicked.onChangeParameter(null);
        // TODO add your handling code here:
    }//GEN-LAST:event_jButtonStopMouseClicked

    private void amplitudeFieldKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_amplitudeFieldKeyPressed
        if (amplitudeField.getText().matches("^.*[^0-9\\.]$")) {
            amplitudeField.setText(amplitudeField.getText().substring(0, amplitudeField.getText().length() - 1));
        }
    }//GEN-LAST:event_amplitudeFieldKeyPressed

    private void frequencyFieldKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_frequencyFieldKeyPressed
        if (frequencyField.getText().matches("^.*[^0-9\\.]$")) {
            frequencyField.setText(frequencyField.getText().substring(0, frequencyField.getText().length() - 1));
        }

        if (!"".equals(frequencyField.getText())) {
            frequencyField.setText(frequencyField.getText().replaceAll("[a-zA-Z]", ""));
            Double selectedFrequency = Double.parseDouble(frequencyField.getText());
            if (selectedFrequency != 0) {
                periodField.setValue(Double.toString(1.0 / selectedFrequency));
            } else {
                periodField.setValue("\u221E");
            }
        } else {
            periodField.setText("");
        }
    }//GEN-LAST:event_frequencyFieldKeyPressed

    private void writeChannelChange(java.awt.event.ItemEvent evt) {
        JRadioButton selected = (JRadioButton) writeChannelChooser.getSelection();
        int selectedValue = Integer.parseInt(selected.getText().replace("A", ""));
        if (selectedValue != currentWriteChannel) {
            if (null != writeChange) {
                writeChange.onChangeParameter(currentWriteChannel = selectedValue);
            }
        }
    }

    /**
     *
     * @return All reading channels selected by User
     */
    private List<JCheckBox> getSelectedInputs() {
        JCheckBox[] inputs = {input0, input1, input2, input3, input4, input5, input6, input7};
        List<JCheckBox> selectedInputs = new ArrayList<>();
        for (JCheckBox input : inputs) {
            if (input.isSelected()) {
                selectedInputs.add(input);
            }
        }
        return selectedInputs;
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel amplitude;
    private javax.swing.JFormattedTextField amplitudeField;
    private javax.swing.JLabel amplitudeLabel;
    private javax.swing.JButton apply;
    private javax.swing.JRadioButton closedLoop;
    private javax.swing.JPanel closedLoopSettings;
    private javax.swing.JButton connect;
    private javax.swing.JPanel controlSettings;
    private javax.swing.JPanel frequency;
    private javax.swing.JFormattedTextField frequencyField;
    private javax.swing.JLabel frequencyLabel;
    private tan.k.view.GraphPanel graphPanel1;
    private tan.k.view.GraphPanel graphPanel2;
    private tan.k.view.GraphPanel graphPanel3;
    private javax.swing.JCheckBox input0;
    private javax.swing.JCheckBox input1;
    private javax.swing.JCheckBox input2;
    private javax.swing.JCheckBox input3;
    private javax.swing.JCheckBox input4;
    private javax.swing.JCheckBox input5;
    private javax.swing.JCheckBox input6;
    private javax.swing.JCheckBox input7;
    private javax.swing.JPanel inputColumn0;
    private javax.swing.JPanel inputColumn1;
    private javax.swing.JPanel inputColumn2;
    private javax.swing.JPanel inputColumn3;
    private javax.swing.JPanel inputTable;
    private javax.swing.JPanel ipPort;
    private javax.swing.JPanel ipPortBox;
    private javax.swing.JFormattedTextField ipPortField;
    private javax.swing.JLabel ipPortLabel;
    private javax.swing.JLabel ipPortToggler;
    private javax.swing.JPanel ipPortWrapper;
    private javax.swing.JButton jButtonPreview;
    private javax.swing.JButton jButtonStop;
    private javax.swing.JLabel jLabelHertz;
    private javax.swing.JLabel jLabelSeconds;
    private javax.swing.JLabel jLabelVoltage;
    private javax.swing.JLabel jLabelVoltage1;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JToggleButton jToggleButtonConfiguration;
    private javax.swing.JPanel loopChooser;
    private javax.swing.ButtonGroup loopTypeChooser;
    private javax.swing.JRadioButton openedLoop;
    private javax.swing.JPanel openedLoopSettings;
    private javax.swing.JRadioButton output0;
    private javax.swing.JRadioButton output1;
    private javax.swing.JRadioButton output2;
    private javax.swing.JRadioButton output3;
    private javax.swing.JRadioButton output4;
    private javax.swing.JRadioButton output5;
    private javax.swing.JRadioButton output6;
    private javax.swing.JRadioButton output7;
    private javax.swing.JPanel outputColumn0;
    private javax.swing.JPanel outputColumn1;
    private javax.swing.JPanel outputColumn2;
    private javax.swing.JPanel outputColumn3;
    private java.awt.Canvas outputPreview;
    private javax.swing.JPanel outputSettings;
    private javax.swing.JPanel outputTable;
    private javax.swing.JPanel period;
    private javax.swing.JFormattedTextField periodField;
    private javax.swing.JLabel periodLabel;
    private javax.swing.JPanel processVariable;
    private javax.swing.JComboBox processVariableField;
    private javax.swing.JLabel processVariableLabel;
    private javax.swing.JToggleButton random;
    private javax.swing.JPanel readBox;
    private javax.swing.JPanel readTitle;
    private javax.swing.JLabel readToggler;
    private javax.swing.JToggleButton sawtooth;
    private javax.swing.JPanel setPoint;
    private javax.swing.JFormattedTextField setPointField;
    private javax.swing.JLabel setPointLabel;
    private javax.swing.JPanel sidebar;
    private javax.swing.JToggleButton sinus;
    private javax.swing.JToggleButton square;
    private javax.swing.JLabel statusConnectedLabel;
    private javax.swing.JToggleButton step;
    private javax.swing.JPanel waveParams;
    private javax.swing.JPanel waveParams1;
    private javax.swing.JPanel waveType;
    private javax.swing.ButtonGroup waveTypeChooser;
    private javax.swing.JPanel write;
    private javax.swing.JPanel writeBox;
    private javax.swing.ButtonGroup writeChannelChooser;
    private javax.swing.JLabel writeToggler;
    // End of variables declaration//GEN-END:variables

    /**
     * @param setPointChange the setPointChange to set
     */
    public void onSetPointChange(ChangeParameterEvent setPointChange) {
        this.setPointChange = setPointChange;
    }

    /**
     * @param processVariableChange the processVariableChange to set
     */
    public void onProcessVariableChange(ChangeParameterEvent processVariableChange) {
        this.processVariableChange = processVariableChange;
    }

    /**
     * @param amplitudeChange the amplitudeChange to set
     */
    public void onAmplitudeChange(ChangeParameterEvent amplitudeChange) {
        this.amplitudeChange = amplitudeChange;
    }

    /**
     * @param periodChange the periodChange to set
     */
    public void onPeriodChange(ChangeParameterEvent periodChange) {
        this.periodChange = periodChange;
    }

    /**
     * @param waveChange the waveChange to set
     */
    public void onWaveChange(ChangeParameterEvent waveChange) {
        this.waveChange = waveChange;
    }

    /**
     * @param loopChange the loopChange to set
     */
    public void onLoopChange(ChangeParameterEvent loopChange) {
        this.loopChange = loopChange;
    }

    /**
     * @param ipChange the ipChange to set
     */
    public void onIpChange(ChangeParameterEvent ipChange) {
        this.ipChange = ipChange;
    }

    /**
     * @param portChange the portChange to set
     */
    public void onPortChange(ChangeParameterEvent portChange) {
        this.portChange = portChange;
    }

    /**
     * @return the currentAmplitide
     */
    public double getCurrentAmplitide() {
        return currentAmplitide;
    }

    /**
     * @return the currentPeriod
     */
    public double getCurrentPeriod() {
        return currentPeriod;
    }

    /**
     * @return the currentWave
     */
    public Wave getCurrentWave() {
        return currentWave;
    }

    /**
     * @return the currentSetPoint
     */
    public double getCurrentSetPoint() {
        return currentSetPoint;
    }

    /**
     * @return the currentPV
     */
    public TankNumber getCurrentPV() {
        return currentPV;
    }

    /**
     * @return the currentLoop
     */
    public Loop getCurrentLoop() {
        return currentLoop;
    }

    /**
     * @return the currentIp
     */
    public String getCurrentIp() {
        return currentIp;
    }

    /**
     * @return the currentPort
     */
    public int getCurrentPort() {
        return currentPort;
    }

    /**
     * @param writeChange the writeChange to set
     */
    public void onWriteChange(ChangeParameterEvent writeChange) {
        this.writeChange = writeChange;
    }

    public void onApplyClicked(ChangeParameterEvent applyClicked) {
        this.applyClicked = applyClicked;
    }

    public void addPointToGraph(String sinal, double t, double d) {
        //System.out.println(t + " " + d + ";");
        switch (sinal) {
            case "Tanque 1":
                graphPanel1.addValue("Tanque 1", t, d);
                break;
            case "Tanque 2":
                graphPanel1.addValue("Tanque 2", t, d);
                break;
            case "Sinal":
                graphPanel2.addValue("Sinal", t, d);
                break;
        }
    }

    public void onConnectedClicked(ChangeParameterEvent changeParameterEvent) {
        this.connectClicked = changeParameterEvent;
    }

    public void setConnectionStatus(ConnectionStatus connectionStatus) {
        System.out.println(connectionStatus.name());
        if (ConnectionStatus.CONNECTED.equals(connectionStatus)) {
            apply.setEnabled(true);
            statusConnectedLabel.setText("Conectado");
            statusConnectedLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/tan/k/resource/ball_green.png")));
        } else {
            apply.setEnabled(false);
            statusConnectedLabel.setText("Não Conectado");
            statusConnectedLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/tan/k/resource/ball_red.png")));
        }
    }

    public void onStopClicked(ChangeParameterEvent changeParameterEvent) {
        this.stopClicked = changeParameterEvent;
    }

    private class ComboItem {

        private TankNumber value;
        private String label;

        public ComboItem(TankNumber value, String label) {
            this.value = value;
            this.label = label;
        }

        public TankNumber getValue() {
            return this.value;
        }

        public String getLabel() {
            return this.label;
        }

        @Override
        public String toString() {
            return label;
        }
    }

    public enum ConnectionStatus {

        CONNECTED, DISCONNECTED, CONNECTING
    }
}
